package com.yinhe.music.yhmusic.search.adapter;

import android.graphics.Color;
import android.support.annotation.Nullable;
import android.widget.ImageView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.yinhe.music.common.GlideHelper.GlideHelper;
import com.yinhe.music.common.utils.KeywordUtil;
import com.yinhe.music.yhmusic.R;
import com.yinhe.music.yhmusic.instrument.InstrumentBean;
import com.yinhe.music.yhmusic.instrument.InstrumentSection;
import com.yinhe.music.yhmusic.log.BlankUtil;

import java.util.List;

/**
 * @author hasee
 * @date 2017/8/15
 */

public class InstrumentAdapter extends BaseQuickAdapter<InstrumentSection, BaseViewHolder> {
    private String key;

    public InstrumentAdapter(@Nullable List<InstrumentSection> data, String key) {
        super(R.layout.fav_album_item, data);
        this.key = key;
    }

    public void setSearchKey(String key) {
        this.key = key;
    }

    @Override
    protected void convert(BaseViewHolder helper, InstrumentSection item) {
        InstrumentBean.InstrumentListBean bean = item.t;
        helper.setText(R.id.album_name, bean.getInstrumentName());
        if (BlankUtil.isBlank(bean.getIntro())) {
            helper.setText(R.id.album_num, "暂无简介");
        } else {
            helper.setText(R.id.album_num, bean.getIntro());
        }

        helper.setGone(R.id.album_frame, false);
        ImageView image = helper.getView(R.id.album_image);
        GlideHelper.setCircleImageResource(image, bean.getIcon(), R.drawable.ic_test_instrument);
        if (key != null) {
            helper.setText(R.id.album_name, KeywordUtil.matcherSearchTitle(Color.parseColor("#1d89ff"), bean.getInstrumentName(), key));
        }
    }
}
